home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / mawk10.zip / KW.C < prev    next >
C/C++ Source or Header  |  1991-10-05  |  2KB  |  96 lines

  1.  
  2. /********************************************
  3. kw.c
  4. copyright 1991, Michael D. Brennan
  5.  
  6. This is a source file for mawk, an implementation of
  7. the AWK programming language.
  8.  
  9. Mawk is distributed without warranty under the terms of
  10. the GNU General Public License, version 2, 1991.
  11. ********************************************/
  12.  
  13.  
  14. /* $Log:    kw.c,v $
  15.  * Revision 3.4.1.1  91/09/14  17:23:37  brennan
  16.  * VERSION 1.0
  17.  * 
  18.  * Revision 3.4  91/08/13  06:51:41  brennan
  19.  * VERSION .9994
  20.  * 
  21.  * Revision 3.3  91/07/18  07:44:45  brennan
  22.  * eliminated useless assignment
  23.  * 
  24.  * Revision 3.2  91/06/28  04:16:56  brennan
  25.  * VERSION 0.999
  26.  * 
  27.  * Revision 3.1  91/06/07  10:27:47  brennan
  28.  * VERSION 0.995
  29.  * 
  30.  * Revision 2.1  91/04/08  08:23:23  brennan
  31.  * VERSION 0.97
  32.  * 
  33. */
  34.  
  35.  
  36. /* kw.c */
  37.  
  38.  
  39. #include "mawk.h"
  40. #include "symtype.h"
  41. #include "parse.h"
  42. #include "init.h"
  43.  
  44.  
  45. static struct kw {
  46. char *text ;
  47. short kw ;
  48. }  keywords[] = {
  49.  
  50. "print", PRINT,
  51. "printf", PRINTF,
  52. "do" , DO ,
  53. "while" , WHILE ,
  54. "for" , FOR ,
  55. "break" , BREAK ,
  56. "continue" , CONTINUE ,
  57. "if" , IF ,
  58. "else", ELSE ,
  59. "in" , IN ,
  60. "delete", DELETE ,
  61. "split" , SPLIT ,
  62. "match" , MATCH_FUNC ,
  63. "BEGIN" , BEGIN,
  64. "END" ,   END ,
  65. "exit" , EXIT ,
  66. "next" , NEXT ,
  67. "return", RETURN,
  68. "getline", GETLINE,
  69. "sub" , SUB,
  70. "gsub", GSUB,
  71. "function", FUNCTION,
  72. (char *) 0 , 0 } ;
  73.  
  74. /* put keywords in the symbol table */
  75. void kw_init()
  76. { register struct kw *p = keywords ;
  77.   register SYMTAB *q ;
  78.  
  79.   while ( p->text )
  80.   { q = insert( p->text ) ;
  81.     q->type = ST_KEYWORD ;
  82.     q->stval.kw = p++ -> kw ;
  83.   }
  84. }
  85.  
  86. /* find a keyword to emit an error message */
  87. char *find_kw_str( kw_token )
  88.   int kw_token ;
  89. { struct kw *p ;
  90.  
  91.   for( p = keywords ; p->text ; p++ )
  92.         if ( p->kw == kw_token )  return p->text ;
  93.   /* search failed */
  94.   return (char *) 0 ;
  95. }
  96.